package com.kly.cashmall.utils;

import java.util.List;

/**
 * @author zxp
 * @since 27/10/21
 */
public class ListIndexFind {
    public ListIndexFind() {
    }

    public static <T, K> int findIndex(List<T> list, K k, ListIndexFind.ObjectCompare<T, K> comparer) {
        if (list != null && k != null) {
            for(int i = 0; i < list.size(); ++i) {
                if (comparer != null && comparer.compare(list.get(i), k)) {
                    return i;
                }
            }

            return -1;
        } else {
            return -1;
        }
    }

    public interface ObjectCompare<T, K> {
        boolean compare(T var1, K var2);
    }

}
